package com.saikuo.service.controller;

import com.saikuo.service.api.ApiResultModel;
import com.saikuo.service.constant.DeliveryType;
import com.saikuo.service.service.IOrderService;
import com.saikuo.service.service.IPayService;
import com.saikuo.service.service.IPlatformService;
import com.saikuo.service.service.IStoreInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jdom.JDOMException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by shanchangyu on 16/10/13.
 */
@Api(value = "商户相关接口", description = "商户确认订单，送药，完成等")
@RestController
@RequestMapping("/platform")
public class PlatformController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IPlatformService platformService;
    @Autowired
    private IStoreInfoService storeInfoService;

    @ApiOperation(value = "根据药店编号查询药店信息")
    @RequestMapping(value = "/getStoreInfoByStoreCode", method = RequestMethod.GET)
    public ApiResultModel getStoreInfoByStoreCode(@RequestParam String storeCode) {
        return storeInfoService.getStoreInfoByStoreCode(storeCode);
    }


    @ApiOperation(value = "修改订单状态,订单状态 2：待收货 3：已完成")
    @RequestMapping(value = "/updateOrder", method = RequestMethod.POST)
    public ApiResultModel updateOrder(@RequestParam String userId,@RequestParam Long orderId, @RequestParam int status) {
        return platformService.updateOrderInfo(userId ,orderId, status);
    }

    @ApiOperation(value = "获取用户所有订单,支持分页;page:页码:默认传递1,订单状态 1:待发货 2:待收货 3:已完成")
    @RequestMapping(value = "/getOrdersByStoreCode", method = RequestMethod.GET)
    public ApiResultModel getOrdersByStoreCode(@RequestParam int storeCode, @RequestParam int orderStatus, @RequestParam int page) {
        return platformService.getOrdersByStoreCode(storeCode, orderStatus, page);
    }

    @ApiOperation(value = "获取订单详情信息")
    @RequestMapping(value = "/getOrderDetailById", method = RequestMethod.GET)
    public ApiResultModel getOrderDetailById(@RequestParam Long orderId) {
        return orderService.getOrderByOrderId(orderId);
    }

}
